package com.ruoyi.web.controller.business;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.ruoyi.business.pojo.dto.*;
import com.ruoyi.ruoyi.business.pojo.vo.ClassifyDetailVo;
import com.ruoyi.ruoyi.business.pojo.vo.ClassifyListVo;
import com.ruoyi.ruoyi.business.service.smo.ClassifyService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * ClassName：CategoryController
 * Package：com.ruoyi.web.controller.business
 * Description：分类
 *
 * @Author：fpy
 * @Create：2025/5/7 - 16:36
 * @Version：v1.0
 */
@RestController
@RequestMapping("/classify")
public class ClassifyController extends BaseController {
    @Resource
    private ClassifyService classifyService;

    /**
     * 分类列表
     *
     * @param: dto
     * @return: com.ruoyi.common.core.domain.AjaxResult<com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.ruoyi.ruoyi.business.pojo.vo.ClassifyListVo>>
     * @author: fpy
     * @date: 2025/5/7 16:58
    **/
    @PostMapping("/list")
    @PreAuthorize("@ss.hasPermi('business:classify:list')")
    public AjaxResult<Page<ClassifyListVo>> list(@RequestBody @Validated ClassifyListDto dto) {
        return classifyService.list(startPage(), dto);
    }

    /**
     * 新增类别
     *
     * @param: dto
     * @return: com.ruoyi.common.core.domain.AjaxResult
     * @author: fpy
     * @date: 2025/5/7 17:16
    **/
    @PostMapping("/add")
    @PreAuthorize("@ss.hasPermi('business:classify:add')")
    public AjaxResult add(@RequestBody @Validated ClassifyAddDto dto) {
        return classifyService.add(dto);
    }

    /**
     * 删除类别
     *
     * @param: dto
     * @return: com.ruoyi.common.core.domain.AjaxResult
     * @author: fpy
     * @date: 2025/5/7 17:28
    **/
    @PostMapping("/remove")
    @PreAuthorize("@ss.hasPermi('business:classify:remove')")
    public AjaxResult remove(@RequestBody @Validated ClassifyRemoveDto dto) {
        return classifyService.remove(dto);
    }

    /**
     * 类别详情
     *
     * @param: dto
     * @return: com.ruoyi.common.core.domain.AjaxResult<com.ruoyi.ruoyi.business.pojo.vo.ClassifyDetailVo>
     * @author: fpy
     * @date: 2025/5/8 9:58
    **/
    @PostMapping("/detail")
    @PreAuthorize("@ss.hasPermi('business:classify:list')")
    public AjaxResult<ClassifyDetailVo> detail(@RequestBody @Validated ClassifyDetailDto dto) {
        return classifyService.detail(dto);
    }

    /**
     * 修改类别
     *
     * @param: dto
     * @return: com.ruoyi.common.core.domain.AjaxResult
     * @author: fpy
     * @date: 2025/5/8 10:31
    **/
    @PostMapping("/edit")
    @PreAuthorize("@ss.hasPermi('business:classify:edit')")
    public AjaxResult edit(@RequestBody @Validated ClassifyEditDto dto) {
        return classifyService.edit(dto);
    }

}
